<template>
  <div
    class="box"
    :style="{ backgroundColor: flexibleItem.backgroundColor }"
    :class="{ isActive: flexibleItem.isOpen }"
    @mouseenter="handleMouseEnter"
  >
    <div v-if="!flexibleItem.isOpen" class="show1">
      <div class="show1_text">
        <h1 style="margin-bottom: 12px">{{ flexibleItem.firstText[0] }}</h1>
        <h1>课程</h1>
        <h2 style="margin-top: 24px">{{ flexibleItem.firstText[1] }}</h2>
      </div>
      <img
        src="@/assets/course/download_right.png"
        style="height: 60px; width: 60px"
      />
    </div>
    <div class="show2" :class="{ texthover: flexibleItem.isShowText }" v-else>
      <div class="left">
        <h1 style="display: inline-block">{{ flexibleItem.nextTopText }}</h1>
        <h2 style="display: inline-block; font-weight: normal">
          适合{{ flexibleItem.firstText[0] }}学段
        </h2>
        <ul>
          <li
            :class="{ lihover: isLight === index }"
            v-for="(item, index) in flexibleItem.classList"
            :key="index"
            @mouseenter="isLight = index"
            @mouseleave="isLight = -1"
          >
            <div
              class="tag"
              :style="{ backgroundColor: flexibleItem.btnColor }"
              :class="{ taghover: isLight === index }"
            >
              {{ item.time }}
            </div>
            <h4>{{ item.name }}</h4>
          </li>
        </ul>
      </div>
      <img
        :class="{ imghover: flexibleItem.isShowPicture }"
        :src="flexibleItem.img"
        alt=""
      />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    flexibleItem: {
      type: Object
    }
  },
  data() {
    return {
      isLight: -1
    }
  },
  methods: {
    handleMouseEnter() {
      this.$emit('openShow', this.flexibleItem.id)
    }
  }
}
</script>

<style scoped>
.box {
  position: relative;
  width: 158px;
  height: 100%;
  border-radius: 20px;
  transition: all 1s ease-in-out;
}
.isActive {
  width: 600px;
}

.show1 {
  position: absolute; /* 保证盒子宽度发生变化时内容不会移动 */
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 0 20px;
}
.show1 .show1_text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.show1 .show1_text > h1 {
  color: #120d2b;
  font-family: AlibabaPuHuiTi2;
  font-size: 40px;
  font-style: normal;
  font-weight: 600;
  line-height: 100%;
  letter-spacing: 5px;
}

.show2 {
  position: absolute;
  left: 30px;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: all 0.3s ease-in-out;
  /* transition: all 0.3s ease-in-out; */
}

.texthover {
  opacity: 1;
}

.left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 350px;
}
.left > h1 {
  color: #120d2b;
  font-family: AlibabaPuHuiTi2;
  font-size: 44px;
  font-style: normal;
  font-weight: 600;
  line-height: 100%;
  margin-bottom: 12px;
}

ul {
  list-style-type: none;
  margin-top: 30px;
}

ul li {
  width: 350px;
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  white-space: nowrap;
  overflow: hidden;
}

.lihover {
  margin-left: 10px;
}

li .tag {
  border-radius: 20px;
  padding: 2px 5px;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  /* filter: brightness(100%); */
}

.taghover {
  filter: brightness(80%);
}

li h4 {
  margin-left: 5px;
  font-size: 14px;
  line-height: 14px;
  font-weight: normal;
  text-overflow: ellipsis; /* 超出部分显示省略号 */
  overflow: hidden; /* 超出部分隐藏 */
}

img {
  margin-left: 10px;
  width: 180px;
  height: 180px;
  transform: translate(0px, 0px);
  opacity: 0;
  transition-delay: 1s;
  transition: all 0.3s ease;
}

.imghover {
  opacity: 1;
}
</style>
